<!--员工信息-->
<template>
  <div class="gas-install-box" :class="!auditStatus || auditStatus!==0?'auditInfo':''">
    <!-- 初始化或已驳回 -->
    <div v-if="auditStatus===null || auditStatus ===2">
      <PageTitle class="boxTitle" :text="title"></PageTitle>
      <div class="detailContent con-box">
        <div class="primary-tit title">申请信息</div>
        <tui-form ref="form">
          <tui-input label="编号" :required="true" :lineLeft="false" placeholder="请输入编号" v-model="formData.jobNumber"></tui-input>
          <tui-input label="岗位" :required="true" :lineLeft="false" placeholder="请输入岗位" v-model="formData.position"></tui-input>
          <tui-input label="姓名" :required="true" :lineLeft="false" placeholder="请输入姓名" v-model="formData.name"></tui-input>
          <tui-input label="联系电话" :required="true" :lineLeft="false" type="number" placeholder="请输入联系电话" v-model="formData.phone" maxlength="11"></tui-input>
          <!-- {{fillUrl+'/'+headerImg}} -->
          <dl class="header">
            <dt>头像</dt>
            <dd @click="choose">
              <uni-icons type="plusempty" color="#999" size="40"></uni-icons>
              <img :src="fillUrl+'/'+headerImg" v-show="headerImg">
            </dd>
          </dl>
          <div class="auditReject">
            <uni-icons type="info" size="22" color="#ff6600"></uni-icons>
            <span v-if="recontent">审核信息：{{recontent}}</span>
            <span v-else>头像必须是半身像，且需要调好合适的比例</span>
          </div>
          <view class="tui-btn__box">
            <tui-button height="84rpx" @click="submit" :disabled="loading" :loading="loading">提交</tui-button>
          </view>
        </tui-form>
      </div>
      <FooterTel></FooterTel>
    </div>
    <!-- 审核中 -->
    <div class="audit-box" v-if="auditStatus === 0">
      <div class="con-box auditContent">
        <div class="icon"></div>
        <dl>
          <dt>审核中</dt>
          <dd>请耐心等待，可随时关注审核进度</dd>
        </dl>
      </div>
      <div class="return" @click="back">返回</div>
    </div>
    <!-- 审核通过  -->
    <WorkCard v-if="auditStatus === 1" :info="formData" :headerImg="headerImg"></WorkCard>
  </div>
</template>

<script>
import PageTitle from '../components/pageTitle.vue'
import FooterTel from '../components/footerTel.vue'
import WorkCard from '../components/workCard.vue'
import { fileURL } from "@/utils/config";
const rules = [{
  name: "jobNumber",
  rule: ["required"],
  msg: ["请输入编号"]
}, {
  name: "position",
  rule: ["required"],
  msg: ["请输入岗位"]
}, {
  name: "name",
  rule: ["required"],
  msg: ["请输入姓名"]
}, {
  name: "phone",
  rule: ["required", "isMobile"],
  msg: ["请输入手机号", "请输入正确的手机号"]
}, {
  name: "imgPath",
  rule: ["required",],
  msg: ["请上传头像"]
}];
export default {
  name: 'Detail',
  components: {
    PageTitle,
    FooterTel,
    WorkCard
  },
  data () {
    return {
      title: null,
      // openid: 'oi8TY6O8cwzuaSky6VNq214MHjVs',
      formData: {
        id: null,
        openid: '',
        jobNumber: '',
        position: '',
        name: '',
        phone: '',
        imgPath: '',
      },
      rules: rules,
      loading: false,
      headerImg: null,
      fillUrl: fileURL,
      recontent: null,
      auditStatus: null, // 0=未审核 1=审核通过 2=已拒绝
      wechatCode: null,
      openId: null,
    };
  },
  async onShow () {
  },
  async onLoad (e) {
    var vm = this;
    vm.title = e.title

    uni.$on('updateImg', function (data) {
      // alert(JSON.stringify(data))
      vm.headerImg = data
      vm.formData.imgPath = data
    })
  },
  created () { },
  async onUnload () {
    // 移除监听
    uni.$off('updateImg');
  },
  methods: {
    getStatus () {
      var vm = this, data = {};
      vm.getId()
      vm.tui.request('/api/workcard/list_h5', 'post', { openid: vm.openId }, false, false, false).then((res) => {
        if (res.code == 200) {
          if (res.data && res.data.length) {
            data = res.data[0]
            vm.formData = {
              id: data.id,
              jobNumber: data.jobNumber,
              position: data.position,
              name: data.name,
              phone: data.phone,
              imgPath: data.imgPath,
            }
            vm.headerImg = data.imgPath
            vm.recontent = data.recontent
            vm.auditStatus = data.status
          }
        }
      }).catch((e) => { })
    },
    async choose () {
      var vm = this;
      uni.chooseImage({
        count: 1,
        sizeType: ["compressed"],
        sourceType: ["album", "camera"],
        success (chooseImageRes) {
          const tempFilePaths = chooseImageRes.tempFilePaths;
          vm.func.goto('/pages/cropper/index?src=' + tempFilePaths);
        },
        fail (err) {
        },
      });
    },
    submit () {
      var vm = this, url = null;
      vm.getId()
      if (!vm.$refs.form) return;
      vm.$refs.form.validate(vm.formData, vm.rules).then(res => {
        console.log(vm.formData)
        vm.formData.openid = vm.openId
        vm.loading = true
        url = vm.formData.id ? '/api/workcard/modify' : '/api/workcard/add'
        vm.tui.request(url, 'post', vm.formData, false, false, true, true).then((res) => {
          // alert(JSON.stringify(res))
          if (res.code == 200) {
            uni.showToast({
              icon: "success",
              title: '添加成功'
            });
            setTimeout(() => {
              vm.back()
              vm.loading = false
              vm.formData = {}
            }, 500);
          }
        }).catch((e) => { })
      }).catch(errors => {
        console.log(errors)
      })
    },
    back () {
      // uni.navigateBack();
      uni.redirectTo({
        url: '/pages/index/index'
      });
    },
    getId () {
      var vm = this;
      vm.openId = uni.getStorageSync('openId')
      // 没有openId跳转获取code页面
      if (!vm.openId) return vm.func.goto('/pages/getCode/index')
    }
  },
  mounted () {
    var vm = this;
    vm.getId()
    vm.getStatus()
  },
};
</script>

<style lang="scss" scoped>
@import "../../static/css/module.scss";
.gas-install-box {
  padding: 10px 0;
  box-sizing: border-box;
  .boxTitle {
    margin: 0 14px 10px;
  }
  .detailContent {
    .imgContent {
      width: auto;
      img {
        width: 100%;
      }
    }
    .header {
      display: flex;
      align-items: center;
      width: 100%;
      padding: 12px 0;
      border-bottom: 1px solid rgba(150, 150, 150, 0.1);
      dt {
        width: 58px;
        font-size: 15px;
        color: #333;
        padding: 0 20px 0 8px;
        position: relative;
        &::before {
          content: "*";
          color: #eb0909;
          position: absolute;
          left: 0;
          top: 0;
        }
      }
      dd {
        width: 80px;
        height: 80px;
        background: #f2f2f2;
        position: relative;
        .uni-icons {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
        }
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
    .auditReject {
      display: flex;
      padding-top: 12px;
      font-size: 15px;
      line-height: 24px;
      color: #f60;
      .uni-icons {
        margin-right: 8px;
      }
    }
  }
  .detailContent,
  .tips {
    padding: 0 18px 20px;
    margin: 14px;
    font-size: 15px;
    line-height: 22px;
    overflow: hidden;
    .title {
      width: 100%;
      height: 30px;
      padding-left: 14px;
      line-height: 30px;
      font-size: 17px;
      font-weight: bold;
      color: #222;
      box-sizing: border-box;
      margin: 10px 0;
    }

    .tui-btn__box {
      padding-top: 30px;
    }
    :v-deep .tui-form__errmsg {
      right: 14px;
      left: 14px;
    }
    :v-deep .tui-textarea__wrap,
    :v-deep .tui-input__wrap {
      padding: 12px 0 12px 8px !important;
    }
    :v-deep .tui-placeholder,
    :v-deep .tui-textarea__label,
    :v-deep .tui-textarea__self,
    :v-deep .uni-input-placeholder,
    :v-deep .tui-input__label,
    :v-deep.tui-input__self {
      font-size: 15px !important;
      uni-text,
      text {
        font-size: 15px !important;
      }
    }
    :v-deep.tui-textarea__wrap {
      align-items: flex-start !important;
    }
    :v-deep .tui-input__required {
      left: 0;
      top: 45%;
    }
  }
}
// 审核中、审核通过
.auditInfo {
  width: 100%;
  height: 100%;
  padding: 0;

  // 审核中
  .audit-box {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: url("https://cqzr-1318844901.cos.ap-chongqing.myqcloud.com/contentImg/icon/auditBj.png")
      center 8% no-repeat;
    background-size: contain;
    position: relative;
    &::before {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      height: 80px;
      background: #1462ff;
      z-index: 0;
    }
    .con-box {
      box-shadow: 0 6px 10px #e7e7e7;
    }
    .auditContent {
      height: 420px;
      margin: 14px 14px 0;
      padding: 80px 0 0;
      box-sizing: border-box;
      position: relative;
      z-index: 1;
      .icon {
        width: 100px;
        height: 100px;
        margin: 0 auto;
        background: url("../../static//image/auditIcon.png") center no-repeat;
        background-size: contain;
      }
      dl {
        text-align: center;
        dt {
          padding: 30px 0 16px;
          font-size: 20px;
          color: #222;
        }
        dd {
          font-size: 14px;
          color: #888;
        }
      }
    }
    .return {
      height: 46px;
      line-height: 46px;
      text-align: center;
      font-size: 15px;
      color: #fff;
      border-radius: 50px;
      background: #1462ff;
      box-shadow: 0 2px 10px #1462ff;
      margin: 50px 14px 0;
    }
  }
}
</style>
<style>
page {
  width: 100%;
  height: 100%;
}
</style>